package com.acwing.partition12;

import java.io.*;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;

/**
 * @author `RKC`
 * @date 2022/1/22 17:50
 */
public class AC1170排队布局 {

    private static final int N = 1010, M = (int) ((1e4 + 10) * 2 + N), INF = 0x3f3f3f3f;
    private static int[] head = new int[N], element = new int[M], next = new int[M], weight = new int[M];
    private static int[] dist = new int[N], cnt = new int[N];
    private static boolean[] inQueue = new boolean[N];

    private static Queue<Integer> queue = new ArrayDeque<>(N);
    private static int n = 0, idx = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] s = reader.readLine().split("\\s+");
        n = Integer.parseInt(s[0]);
        Arrays.fill(head, -1);
        for (int i = 1; i < n; i++) createEdge(i + 1, i, 0);
        int k1 = Integer.parseInt(s[1]), k2 = Integer.parseInt(s[2]);
        while (k1-- > 0) {
            s = reader.readLine().split("\\s+");
            int u = Integer.parseInt(s[0]), v = Integer.parseInt(s[1]), w = Integer.parseInt(s[2]);
            if (u > v) {
                int t = u;
                u = v;
                v = t;
            }
            createEdge(u, v, w);
        }
        while (k2-- > 0) {
            s = reader.readLine().split("\\s+");
            int u = Integer.parseInt(s[0]), v = Integer.parseInt(s[1]), w = Integer.parseInt(s[2]);
            if (u > v) {
                int t = u;
                u = v;
                v = t;
            }
            createEdge(v, u, -w);
        }
        if (spfa(n)) writer.write(-1 + "\n");
        else {
            spfa(1);
            if (dist[n] == INF) writer.write(-2 + "\n");
            else writer.write(dist[n] + "\n");
        }
        writer.flush();
    }

    private static boolean spfa(int size) {
        queue.clear();
        for (int i = 1; i <= n; i++) {
            dist[i] = INF;
            inQueue[i] = false;
            cnt[i] = 0;
        }
        for (int i = 1; i <= size; i++) {
            queue.add(i);
            inQueue[i] = true;
            dist[i] = 0;
        }
        while (!queue.isEmpty()) {
            int u = queue.poll();
            inQueue[u] = false;
            for (int i = head[u]; i != -1; i = next[i]) {
                int v = element[i];
                if (dist[v] > dist[u] + weight[i]) {
                    dist[v] = dist[u] + weight[i];
                    cnt[v] = cnt[u] + 1;
                    if (cnt[v] >= n) return true;
                    if (inQueue[v]) continue;
                    queue.add(v);
                    inQueue[v] = true;
                }
            }
        }
        return false;
    }

    private static void createEdge(int u, int v, int w) {
        element[idx] = v;
        next[idx] = head[u];
        head[u] = idx;
        weight[idx++] = w;
    }
}
